# 创建标准属性,token可能会过期，最好每次更新一下

import pandas as pd
from dao.mysqlhelper import MySQLHelper
from base.base import Base
import json

# 读取Excel文件，文件里的值最好都设置成文本
file_path = 'D:\\IOT3.0\\2024.09\\实体赋码平台\\标准属性_1008新增.xlsx'  # 替换为你的文件路径
df = pd.read_excel(file_path, engine='openpyxl')

# 遍历每一行数据
for index, row in df.iterrows():
    base=Base()
    url='http://192.168.143.99:10074/gateway/code-one/entityAttributeDict/save'
    param_type='application/json'
    headers={
        'content-type':'application/json',
        'authorization':'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1aWQiOiIxODM4NTE3NDc2ODU5MTcwODE3Iiwic3ViIjoienpoIiwiYXVkIjoidGVuYW50IiwidW5hbWUiOiJ6emgiLCJhcHBJZCI6ImRlZmF1bHRBcHBJZCIsImlzcyI6ImlkYWFzIiwidGVuYW50SWQiOiJkZWZhdWx0VGVuYW50SWQiLCJ1dHlwZSI6InVzZXIiLCJybmQiOiIyejdtNXE5MyIsImV4cCI6MTcyODQzMzgzMSwiaWF0IjoxNzI4MzQ3NDMxfQ.SVUzxgdsGjrJB9ScUERu3YK27I-2Zm0NA6P-87jNAYI'
    }
    data={
        "configName": row['属性名称'],
        "configKey": row['属性code'],
        "dataType": "String",
        "status": 0,
        "configScope": row['文本长度'],
        "attributeType": "0"
    }

    try:
        res=json.loads(base.send_post(url,param_type,headers=headers,data=data))

        # 检查请求是否成功
        if res['msg'] == '新增成功':
            print(f"成功提交第 {index + 1} 行数据: {data}")
        else:
            print(f"第 {index + 1} 行数据提交失败，状态码: {res.status_code}, 响应: {res.text}")

    except Exception as e:
        print(f"调用接口时发生错误: {e}")